package com.iplant.wms.controller.mrp;

import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.annotation.trace.TraceAPI;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.wms.service.WMSService;
import com.iplant.wms.service.po.mrp.MRPDelivery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("/api/MRPDelivery")
public class MRPDeliveryController extends BasicController<MRPDelivery> {


    @Autowired
    WMSService mWMSService;

    public MRPDeliveryController() {
        super(MRPDelivery.class);
    }


    @TraceAPI("查询完整物料配送需求")
    @GetMapping("/DetailAll")
    public Object DetailAll(HttpServletRequest request) {
        Object wResult;
        try {
            BMSEmployee wLoginUser = GetSession(request);


            Calendar wStartDate = StringUtils.parseCalendar(request.getParameter("StartDate"));
            Calendar wEndDate = StringUtils.parseCalendar(request.getParameter("EndDate"));

            Pagination wPagination=GetPagination(request);


            ServiceResult<List<MRPDelivery>> wServiceResult = mWMSService.MRP_SelectDeliveryListByDate(wLoginUser, wStartDate, wEndDate,wPagination);


            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            log.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString());
        }
        return wResult;
    }


}
